#include "book_mod_dialog.h"
#include "ui_book_mod_dialog.h"

book_mod_Dialog::book_mod_Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::book_mod_Dialog),
    book({"","","","","","",""}),
    flag(false)
{
    ui->setupUi(this);
}

book_mod_Dialog::~book_mod_Dialog()
{
    delete ui;
}

void book_mod_Dialog::printfData()
{
    ui->lineEdit_number->setText(book[0]);
    ui->lineEdit_ISBN->setText(book[1]);
    ui->lineEdit_name->setText(book[2]);
    ui->lineEdit_writer->setText(book[3]);
    ui->lineEdit_price->setText(book[4]);
    ui->spinBox_num->setValue(book[5].toUInt());
    ui->dateEdit_PublishTime->setDate(QDate::fromString(book[6],"yyyy年MM月"));
    ui->comboBox_PublishUnit->setEditText(book[7]);
}

void book_mod_Dialog::closeEvent(QCloseEvent *event)
{
    this->close();
}

void book_mod_Dialog::on_pushButton_OK_clicked()
{
    this->flag=true;
    book[0]=ui->lineEdit_number->text();
    book[1]=ui->lineEdit_ISBN->text();
    book[2]= ui->lineEdit_name->text();
    book[3]=ui->lineEdit_writer->text();
    book[4]=ui->lineEdit_price->text();
    book[5]=QString::number(ui->spinBox_num->value());
    book[6]=ui->dateEdit_PublishTime->date().toString("yyyy年MM月");
    book[7]=ui->comboBox_PublishUnit->currentText();

    this->close();
}

void book_mod_Dialog::on_pushButton_2_clicked()
{
    this->close();
}
